﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Server.API
{
    class ApiService
    {
        CPPEI.Net.Original.UDP.UDPClient _client;

        public void Start(string ip, int port)
        {
            if (_client == null)
            {
                try
                {
                    _client = new Net.Original.UDP.UDPClient(port, new ApiHandlerFactory());
                    _client.StartReceive(ip);
                }
                catch(Exception ex)
                {
                    _client = null;
                    throw ex;
                }
            }
        }

        public void Stop()
        {
            if (_client != null)
            {
                _client.StopReceive();
            }
        }
    }
}
